﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LoU.Dungeons
{
    public class MilitaryBuild
    {
        private void InitRecruitSpeed()
        {
            this.RecruitSpeed = new Dictionary<UnitType, double>();
            foreach (UnitType type in Enum.GetValues(typeof(UnitType)))
            {
                this.RecruitSpeed.Add(type, int.MaxValue);
            }
        }

        public MilitaryBuild(UnitType type, double recruitSpeed, int maxTS)
        {
            this.InitRecruitSpeed();
            this.RecruitSpeed[type] = recruitSpeed;
            this.MaxTS = maxTS * 1000;
        }
        public MilitaryBuild(double zerk, double ranger, double guardian, int maxTS)
        {
            this.InitRecruitSpeed();
            this.RecruitSpeed[UnitType.Berserker] = zerk;
            this.RecruitSpeed[UnitType.Ranger] = ranger;
            this.RecruitSpeed[UnitType.Gardian] = guardian;
            this.MaxTS = maxTS * 1000;
        }
        public Dictionary<UnitType, double> RecruitSpeed { get; set; }
        public int MaxTS { get; set; }
        public override string ToString()
        {
            return this.MaxTS / 1000 + "kTS : " + 
                string.Join(", ", this.RecruitSpeed.Where(a => a.Value != int.MaxValue)
                    .Select(a => string.Format("{0}s {1}", a.Value, Enum.GetName(typeof(UnitType), a.Key))).ToArray());
        }

        public IEnumerable<UnitType> AvailableUnits { get { return this.RecruitSpeed.Where(r => r.Value != int.MaxValue).Select(r => r.Key).Distinct(); } }
    }
}
